import 'package:lcapp/data/comment_data_entity.dart';
import 'package:lcapp/data/user_data_entity.dart';

commentDataEntityFromJson(CommentDataEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['userId'] != null) {
		data.userId = json['userId'] is String
				? int.tryParse(json['userId'])
				: json['userId'].toInt();
	}
	if (json['username'] != null) {
		data.username = json['username'].toString();
	}
	if (json['userName'] != null) {
		data.userName = json['userName'].toString();
	}
	if (json['image'] != null) {
		data.image = json['image'].toString();
	}
	if (json['content'] != null) {
		data.content = json['content'].toString();
	}
	if (json['entryId'] != null) {
		data.entryId = json['entryId'] is String
				? int.tryParse(json['entryId'])
				: json['entryId'].toInt();
	}
	if (json['replies'] != null) {
		data.replies = (json['replies'] as List).map((v) => CommentDataEntity().fromJson(v)).toList();
	}
	if (json['likes'] != null) {
		data.likes = json['likes'] is String
				? int.tryParse(json['likes'])
				: json['likes'].toInt();
	}
	if (json['timeDiffer'] != null) {
		data.timeDiffer = json['timeDiffer'].toString();
	}
	if (json['address'] != null) {
		data.address = json['address'].toString();
	}
	if (json['reply'] != null) {
		data.reply = json['reply'] is String
				? int.tryParse(json['reply'])
				: json['reply'].toInt();
	}
	if (json['operation'] != null) {
		data.operation = json['operation'] is String
				? int.tryParse(json['operation'])
				: json['operation'].toInt();
	}
	if (json['author'] != null) {
		data.author = json['author'] is String
				? int.tryParse(json['author'])
				: json['author'].toInt();
	}
	if (json['toUserName'] != null) {
		data.toUserName = json['toUserName'].toString();
	}
	if (json['type'] != null) {
		data.type = json['type'] is String
				? int.tryParse(json['type'])
				: json['type'].toInt();
	}
	return data;
}

Map<String, dynamic> commentDataEntityToJson(CommentDataEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['userId'] = entity.userId;
	data['username'] = entity.username;
	data['userName'] = entity.userName;
	data['image'] = entity.image;
	data['content'] = entity.content;
	data['entryId'] = entity.entryId;
	data['replies'] =  entity.replies?.map((v) => v.toJson())?.toList();
	data['likes'] = entity.likes;
	data['timeDiffer'] = entity.timeDiffer;
	data['address'] = entity.address;
	data['reply'] = entity.reply;
	data['operation'] = entity.operation;
	data['author'] = entity.author;
	data['toUserName'] = entity.toUserName;
	data['type'] = entity.type;
	return data;
}